package com.sport.service;

import com.sport.context.BaseContext;
import com.sport.mapper.TeamMapper;
import com.sport.pojo.dto.ApplyPlayerDto;
import com.sport.pojo.dto.CreateTeamDto;
import com.sport.pojo.dto.TeamRankDto;
import com.sport.pojo.entity.*;
import com.sport.pojo.vo.TeamUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @ClassName TeamServiceImpl
 * @Description TODO
 * @Author dumx
 * @Date 2023/12/15 14:47
 */
@Service
public class TeamServiceImpl implements TeamService{
    @Autowired
    private TeamMapper teamMapper;


    @Override
    public int userIntoTeam(String userId,String userName) {
        return teamMapper.userIntoTeam(userId,userName);
    }

    @Override
    public List<FootballPlayer> showAllPlayersIn(String teamId) {
        return teamMapper.showAllPlayersIn(teamId);
    }

    @Override
    public Team showTeamMessageBy(String teamId) {
        return teamMapper.showTeamMessageBy(teamId);
    }

    @Override
    public List<Team> showAllTeam() {
        return teamMapper.showAllTeams();
    }

    @Override
    public Team showTeamDetails(String teamName) {
        return teamMapper.showTeamDetails(teamName);
    }

    @Override
    public List<TeamRankDto> getTeamRankList() {
        return teamMapper.getTeamRankList();
    }

    @Override
    public int applyFor(String userName, String teamId) {
        return teamMapper.applyFor(userName,teamId);
    }

    @Override
    public List<ApplyPlayerDto> getApplyTable(String applicationTeamId) {
        return teamMapper.getApplyTable(applicationTeamId);
    }

    @Override
    public int applyYesUserIntoTeamByName(TeamUserVo teamUserVo) {
        int info = teamMapper.applyYesUserIntoTeamByName(teamUserVo);
        if (info!=0){
            return teamMapper.deleteApplyMessage(teamUserVo);
        }else {
            return info;
        }

    }
    @Override
    public int applyNoUserIntoTeamByName(TeamUserVo teamUserVo) {
            return teamMapper.deleteApplyMessage(teamUserVo);
    }

    @Override
    public List<LeagueScoreboardDto> showLeagueScoreboard() {
        return teamMapper.showLeagueScoreboard();
    }
    @Override
    public List<Team> searchTeam(String teamName) {
        return teamMapper.searchTeam(teamName);
    }

    @Override
    public int creatTeam(CreateTeamDto createTeamDto) {
        createTeamDto.setCreateTime(LocalDateTime.now().toString());
        createTeamDto.setTeamId(UUID.randomUUID().toString());
        createTeamDto.setTeamLeaderId(BaseContext.getCurrentId());
        return teamMapper.creatTeam(createTeamDto);
    }
}
